#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<pthread.h>
#include<string.h>

pthread_cond_t cond;
pthread_mutex_t mutex;

void *r1(void* arg)
{
    while(1)
    {   
        printf("1");
        pthread_cond_signal(&cond);
        sleep(1);
    }
}

void *r2(void* arg)
{
    while(1)
    {   

        pthread_cond_wait(&cond, &mutex);//P operate 
        printf("activities~~~\n");//work
    }
}
int main()
{   
    pthread_t t1,t2;
    pthread_cond_init(&cond, NULL);
    pthread_mutex_init(&mutex, NULL);

    pthread_create(&t1, NULL, r1, NULL);
    pthread_create(&t2, NULL, r2, NULL);//参数：1.id, 2.属性，为null时为默认属性，3.线程建立时所以执行的函数，4.传给线程的参数

    pthread_join(t1, NULL);
    pthread_join(t2, NULL);
    
    pthread_cond_destroy(&cond);
    pthread_mutex_destroy(&mutex);
    return 0;
}